﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData;

namespace ZFS.ServerLibrary
{
    public partial class BaseService : IBaseService
    {
        public byte[] GetGroups(string search)
        {
            var GroupList = Factory.GetGroupManager().GetGroups(search);
            byte[] bytes = ZipTools.CompressionObject(GroupList);
            return bytes;
        }

        public byte[] GetGroupUsers(string groupID)
        {
            var userViewList = Factory.GetGroupManager().GetGroupUsers(groupID);
            byte[] bytes = ZipTools.CompressionObject(userViewList);
            return bytes;
        }

        public byte[] GetGroupFuncs(string groupCode)
        {
            var gpFuncList = Factory.GetGroupManager().GetGroupFuncs(groupCode);
            byte[] bytes = ZipTools.CompressionObject(gpFuncList);
            return bytes;
        }

        public bool UpdateGroupFunc(byte[] group, byte[] userList, byte[] funcList)
        {
            var Group = ZipTools.DecompressionObject(group) as tb_Group;
            var Userlist = ZipTools.DecompressionObject(userList) as List<View_GroupUser>;
            var FuncList = ZipTools.DecompressionObject(funcList) as List<tb_GroupFunc>;

            return Factory.GetGroupManager().UpdateGroupFunc(Group, Userlist, FuncList);
        }

        public bool RemovebyGroup(int id)
        {
            return Factory.GetGroupManager().Remove(id);
        }

        public byte[] GetModelsByGroup(byte[] search)
        {
            var Group = ZipTools.DecompressionObject(search) as tb_Group;
            var gpFuncList = Factory.GetGroupManager().GetModels(Group);
            byte[] bytes = ZipTools.CompressionObject(gpFuncList);
            return bytes;
        }

        public byte[] GetPagingModelsByGroup(int pageIndex, int pageSize, out int totalCount,
            byte[] search,
            bool Asc = false)
        {
            var Group = ZipTools.DecompressionObject(search) as tb_Group;
            var gpFuncList = Factory.GetGroupManager().GetPagingModels(pageIndex, pageSize, out totalCount, Group, Asc);
            byte[] bytes = ZipTools.CompressionObject(gpFuncList);
            return bytes;
        }

        public bool DeleteEntityByGroup(byte[] entity)
        {
            var Group = ZipTools.DecompressionObject(entity) as tb_Group;
            var result = Factory.GetGroupManager().DeleteEntity(Group);
            return result;
        }

        public bool UpdateEntityByGroup(byte[] entity)
        {
            var Group = ZipTools.DecompressionObject(entity) as tb_Group;
            var result = Factory.GetGroupManager().UpdateEntity(Group);
            return result;
        }

        public byte[] AddEntityByGroup(byte[] entity)
        {
            var Group = ZipTools.DecompressionObject(entity) as tb_Group;
            var result = Factory.GetGroupManager().AddEntity(Group);
            byte[] bytes = ZipTools.CompressionObject(result);
            return bytes;
        }

        public bool ExistEntityByGroup(byte[] search)
        {
            var Group = ZipTools.DecompressionObject(search) as tb_Group;
            var result = Factory.GetGroupManager().ExistEntity(Group);
            return result;
        }
    }
}
